package com.hai.qtalk.service;

import java.util.List;

import com.hai.qtalk.base.BaseDAO;
import com.hai.qtalk.bean.Friendship;
import com.hai.qtalk.bean.Group;

/**
 * 关系处理的业务逻辑类
 * 对关系进行增删查改
 * @author xinhai
 *
 */
public class FriendshipService {

	private static BaseDAO<Friendship> fDao = new BaseDAO<Friendship>();
	
	/**
	 * 添加好友
	 * @param f
	 */
	public static void addFriend(Friendship f){
		fDao.save(f);
	}
	
	/**
	 * 删除好友
	 * @param f
	 */
	public static void deleteFriend(Friendship f){
		fDao.delete(f);
	}
	
	/**
	 * 根据用户和好友ID找到两个人的关系
	 * @param hostId
	 * @param friendId
	 * @return
	 */
	public static Friendship findFriendship(int hostId,int friendId){
		return fDao.find("select f from Friendship f Where f.userByFriendId.UId='"+friendId+"'and f.userByHostId.UId='"+hostId+"'");
	}
	
	/**
	 * 根据用户ID找到用户的所有好友关系
	 * @param hostId
	 * @return
	 */
	public static List<Friendship> findAllFriendship(int hostId){
		List<Friendship> list=fDao.list("select f from Friendship f where f.userByHostId.UId = '"+hostId+"'");
//		System.out.println("Friednship list为");
//		for(Friendship f:list){
//			System.out.println(f.getFId());
//		}
		return list;
	}
}
